﻿using System;

namespace 第十题
{
    interface VoiceBehavior
    {
        void quak();
    }
    class Voice1 : VoiceBehavior
    {
        public virtual void quak()
        {
            Console.WriteLine("嘎嘎叫");
        }
    }
    class Voice2 : VoiceBehavior
    {
        public virtual void quak()
        {
            Console.WriteLine("呱呱叫");
        }
    }
    class Voice3 : VoiceBehavior
    {
        public virtual void quak()
        {
            Console.WriteLine("不会叫");
        }
    }

    interface swimbehavior
    {
        void swim();
    }
    class swim1 : swimbehavior
    {
        public virtual void swim()
        {
            Console.WriteLine("用翅膀游泳");
        }
    }
    class swim2 : swimbehavior
    {
        public virtual void swim()
        {
            Console.WriteLine("不用翅膀游泳");
        }
    }
    class Duck
    {
        public String name { get; set; }
        public VoiceBehavior voice { get; set; }
        public swimbehavior swim { get; set; }
        public void preformswim()
        {
            swim.swim();
        }
        public void preformVoice()
        {
            voice.quak();
        }
        public void Display()
        {
            Console.WriteLine("这是一只{0}", name);
        }
    }

    class MailardDuck : Duck
    {
        public MailardDuck()
        {
            name = "MailardDuck";
            voice = new Voice1();
            swim = new swim1();

        }

    }
    class RedheadDuck : Duck
    {
        public RedheadDuck()
        {
            name = "RedheadDuck";
            voice = new Voice2();
            swim = new swim1();
        }
    }
    class RobberDuck : Duck
    {
        public RobberDuck()
        {
            name = "RobberDuck";
            voice = new Voice3();
            swim = new swim2();
        }
    }
    internal class Program
    {
        static void Main(string[] args)
        {
            Duck duck1 = new MailardDuck();
            Duck duck2 = new RedheadDuck();
            Duck duck3 = new RobberDuck();
            duck1.Display();
            duck1.preformVoice();
            duck1.preformswim();
            duck2.Display();
            duck2.preformVoice();
            duck2.preformswim();
            duck3.Display();
            duck3.preformVoice();
            duck3.preformswim();
        }
    }
}
